package com.wman.sheep.common.utils;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.wman.sheep.R;
import com.wman.sheep.common.application.AbsAppContext;

public class ToastUtil {

    //连续吐司
    public static void showTextToast(String msg) {
        if (StringUtils.isEmpty(msg)) {
            return;
        }

        try {
            Activity activity = AbsAppContext.getActivityManager().currentActivity();
            showToast(activity, msg, 0);
        } catch (Exception e) {
            e.printStackTrace();
            showToast(AbsAppContext.context(), msg, 0);
        }
    }

    public static void showToast(Context context, String msg, int icon) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_toast, null);
        ((TextView) view.findViewById(R.id.title_tv)).setText(msg);
        if (icon != 0) {
            ((ImageView) view.findViewById(R.id.icon_iv)).setImageResource(icon);
            ((ImageView) view.findViewById(R.id.icon_iv)).setVisibility(View.VISIBLE);
        }

        ToastUtils.showCustomShort(view);
    }

    public static void cancel() {
        ToastUtils.cancel();
    }
}
